package leetcode_2501_2600;

import java.util.Arrays;

public class LeeCode_2567 {
    public static void main(String[] args) {
        System.out.println(minimizeSum(new int[]{58, 42, 8, 75, 28}));
    }
    private static int minimizeSum(int[] nums) {
        int n = nums.length;
        if (n <= 3)
            return 0;
        Arrays.sort(nums);
        return Math.min(nums[n - 1] - nums[2], Math.min(nums[n - 3] - nums[0], nums[n - 2] - nums[1]));
    }
}
